/**
 * Created by lional on 16/10/3.
 */

jGame.GameObject = cc.Class.extend(/** @lends jGame.GameObject# */{

    _name: "GameObject",                     ///<a string label, an user defined string to identify this object

    ctor: function(){
        //cc.log("jGame.GameObject[" + this._name + "]#ctor()");
    },

    /**
     * Changes the name that is used to identify the node easily.
     * @function
     * @param {String} name
     */
    setName: function(name){
        this._name = name;
    },

    /**
     * Returns a string that is used to identify the node.
     * @function
     * @returns {string} A string that identifies the node.
     */
    getName: function(){
        return this._name;
    },

    trace: function (sender, touchtype, event) {
        var log = "";
        var long_name = "";
        var name = "";
        var tag = "";
        var uData = "";
        if(sender && sender instanceof cc.Node) {
            var parent = sender.getParent();
            if(parent) {
                long_name += parent.getName() + ".";
            }
            name += sender.getName();
            long_name += name;
            tag = sender.getTag();
            uData = sender.getUserData();
            if(tag) {
                log += ", {tag:" + tag + "}";
            }
            if(uData) {
                log += ", {data:" + uData + "}";
            }
        }
        if(typeof touchtype != "undefined") {
            if(typeof touchtype === "object") {
                if(touchtype instanceof cc.Touch) {
                    log += ", " + JSON.stringify(touchtype.getLocation());
                }else {
                    log += ", " + touchtype;
                }
            }else {
                log += ", " + touchtype;
            }
        }
        if(typeof event != "undefined") {
            if(typeof event === "object") {
                if(event instanceof cc.Event) {
                    if(!name) {
                        name = event.getCurrentTarget().getName();
                        long_name += name;
                    }
                    log += ", {code:" + event.getEventCode() + ", type:" + event.getType() + "}"
                }else {
                    log += ", " + event;
                }
            }else {
                log += ", " + event;
            }
        }
        cc.log("jGame." + this.toString() + "#trace(" + long_name + ")" + log);
        var event = new jGame.EventCustom("jGame.GameObject.onTrace");
        event.setUserData(long_name + "#" + uData);
        jGame.eventManager.dispatchEvent(event);
    },

    toString : function () {
        return this._name;
    },

});